﻿//-----------------------------------------------------------------------
// <copyright file="CarrierContext.cs" company="SLWY Enterprises">
// * Copyright (C) 2017 四川商旅无忧科技有限公司 版权所有。
// * version : 1.0
// * author  : qinchaoyue
// * FileName: CarrierContext.cs
// * history : created by qinchaoyue 2018-01-04 11:27:52
// </copyright>
//-----------------------------------------------------------------------

using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Slwy.Core.Entities;
using Slwy.MySql.Contracts;
using Slwy.Utility.ConfigurManager;

namespace Slwy.Core.Repository.EF
{
    public class CarrierContext : DbContext
    {
        private readonly IMySqlConnection _mySqlConnection;

        public CarrierContext(IMySqlConnection mySqlConnection)
        {
            _mySqlConnection = mySqlConnection;
        }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            string connectionString = this._mySqlConnection.GetWriteConnectionString();
            optionsBuilder.UseMySQL(connectionString);
        }

        protected override void OnModelCreating(ModelBuilder builder)
        {
            builder.Entity<CarrierInfo>().HasKey(m => m.KeyId);
            base.OnModelCreating(builder);
        }

        public DbSet<CarrierInfo> CarrierInfo { get; set; }
    }
}
